package com.gjw.cor;

import com.gjw.planeWar.EnemyPlane;
import com.gjw.planeWar.GameObject;
import com.gjw.planeWar.HeroPlane;

/**
 * @author gjw19
 * @date 2019/5/19
 */
public class HeroEnemyCollider implements Collider {
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if (o1 instanceof HeroPlane && o2 instanceof EnemyPlane) {
            HeroPlane h = (HeroPlane) o1;
            EnemyPlane e = (EnemyPlane) o2;
            if (h.getRect().intersects(e.getRect())) {
                h.die();
                e.die();
                return false;
            }
        } else if (o1 instanceof EnemyPlane && o2 instanceof HeroPlane) {
            return collide(o2, o1);
        }
        return true;
    }
}
